/*******************************************************************************
 * Copyright (c) 2013 Prometheus Consulting
 *
 *     Licensed under the Apache License, Version 2.0 (the "License"); you may
 *     not use this file except in compliance with the License. You may obtain
 *     a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *     WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 *     License for the specific language governing permissions and limitations
 *     under the License.
 *******************************************************************************/
package nz.co.senanque.pizzaorder;

import org.springframework.context.support.MessageSourceAccessor;

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;

public class HomeLayout extends CustomComponent {

	@AutoGenerated
	private VerticalLayout mainLayout;
	@AutoGenerated
	private Panel panel_1;
	@AutoGenerated
	private VerticalLayout verticalLayout_2;
	@AutoGenerated
	private Label label_1;
	@AutoGenerated
	private Embedded embedded_1;
	private MessageSourceAccessor m_messageSourceAccessor;

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public HomeLayout() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
	}

	@AutoGenerated
	private VerticalLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new VerticalLayout();
		mainLayout.setImmediate(false);
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		mainLayout.setMargin(false);
		mainLayout.setSpacing(true);
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// embedded_1
//		embedded_1 = new Embedded();
//		embedded_1.setImmediate(false);
//		embedded_1.setWidth("-1px");
//		embedded_1.setHeight("-1px");
//		embedded_1
//				.setSource(new ExternalResource(
//						"http://2.bp.blogspot.com/-eQ_JY5hJJAA/TdB0-SRLxWI/AAAAAAAAANk/Lu5drUqHlTM/s1600/pizza-margherita.jpg"));
//		embedded_1.setType(1);
//		embedded_1.setMimeType("image/png");
//		mainLayout.addComponent(embedded_1);
//		mainLayout.setComponentAlignment(embedded_1, new Alignment(20));
		
		// panel_1
		panel_1 = buildPanel_1();
		mainLayout.addComponent(panel_1);
		mainLayout.setComponentAlignment(panel_1, new Alignment(20));
		
		return mainLayout;
	}

	@AutoGenerated
	private Panel buildPanel_1() {
		// common part: create layout
		panel_1 = new Panel();
		panel_1.setImmediate(false);
		panel_1.setWidth("40%");
		panel_1.setHeight("30%");
		
		// verticalLayout_2
		verticalLayout_2 = buildVerticalLayout_2();
		panel_1.setContent(verticalLayout_2);
		
		return panel_1;
	}

	@AutoGenerated
	private VerticalLayout buildVerticalLayout_2() {
		// common part: create layout
		verticalLayout_2 = new VerticalLayout();
		verticalLayout_2.setImmediate(false);
		verticalLayout_2.setWidth("-1px");
		verticalLayout_2.setHeight("-1px");
		verticalLayout_2.setMargin(false);
		
		// label_1
		label_1 = new Label();
		label_1.setStyleName("home-message");
		label_1.setImmediate(false);
		label_1.setWidth("500px");
		label_1.setHeight("-1px");
		label_1.setValue("Label");
		label_1.setContentMode(3);
		verticalLayout_2.addComponent(label_1);
		
		return verticalLayout_2;
	}
	public void setMessageSourceAccessor(
			MessageSourceAccessor messageSourceAccessor) {
		m_messageSourceAccessor = messageSourceAccessor;
		String m = m_messageSourceAccessor.getMessage("home.message");
		label_1.setValue(m);
	}

}
